using System;
using System.Collections.Generic;
using System.Text;

namespace MTC12
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Globalization.ChineseLunisolarCalendar clc = new System.Globalization.ChineseLunisolarCalendar();
            DateTime date = clc.ToDateTime(2007, 1, 1, 1, 1, 1, 1);
            int cc = 0, b = System.Threading.Interlocked.Increment(ref cc);

            System.IO.StreamReader sr = new System.IO.StreamReader("test15");
            List<string> ss = new List<string>();
            int i = 0;
            string s;
            for(s = sr.ReadLine(); i<100000 & s != null; i++,s = sr.ReadLine())
                ss.Add(s.Substring(s.IndexOf(' ')+1));
            List<int> u = new List<int>(), v = new List<int>();
            for(; s != null; i++,s = sr.ReadLine())
            {
                int a = s.IndexOf(' ');
                u.Add(int.Parse(s.Substring(0, a)));
                v.Add(int.Parse(s.Substring(a + 1)));
            }
            Distance d = new Distance();
            d.process(ss.ToArray());
            double[] ds = d.query(u.ToArray(), v.ToArray());
            double total = 0;
            foreach(double t in ds)
            {
                total += t;
            }
            Console.WriteLine(total);
        }
    }
}
